import { createRouter, createWebHistory } from 'vue-router'
// import { useUserStore } from '@/stores'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/login', component: () => import('@/views/login/LoginPage.vue') }, //登录页
    {
      path: '/',
      component: () => import('@/views/layout/LayoutContainer.vue'),
      redirect: '/home/home',
      children: [
        {
          path: '/home/home',
          component: () => import('@/views/home/HomePage.vue')
        },
        {
          path: '/employee/manage',
          component: () => import('@/views/employee/EmployeeManage.vue')
        },
        {
          path: '/hire/manage',
          component: () => import('@/views/hire/HireManage.vue')
        },
        {
          path: '/salary/manage',
          component: () => import('@/views/salary/SalaryManage.vue')
        },
        {
          path: '/attendance/manage',
          component: () => import('@/views/attendance/AttendanceManage.vue')
        },
        {
          path: '/professional/training',
          component: () => import('@/views/professional/TrainingPrograms.vue')
        },
        {
          path: '/professional/development',
          component: () => import('@/views/professional/DevelopmentPlanning.vue')
        },
        {
          path: '/professional/evaluation',
          component: () => import('@/views/professional/Evaluation.vue')
        }
      ]
    }
  ]
})

router.beforeEach((to) => {
  // 如果没有token, 且访问的是非登录页，拦截到登录，其他情况正常放行
  
  // 获取存储在localStorage中的token
  const token = localStorage.getItem('token');
  if (!token && to.path !== '/login') return '/login'
})


export default router
